<template>
  <div>
    <h3>管理员信息</h3>
    <ul class="setting">
      <li>姓名：</li>
      <li>注册时间：</li>
      <li>管理员权限：</li>
      <li>管理员id：</li>
      <li>更换头像：</li>
      <li>
        <el-upload
          class="avatar-uploader"
          action="https://jsonplaceholder.typicode.com/posts/"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          :before-upload="beforeAvatarUpload"
        >
          <img v-if="imageUrl" :src="imageUrl" class="avatar" />
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </li>
    </ul>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        imageUrl: ''
      };
    },
    methods: {
      handleAvatarSuccess(res, file) {
        this.imageUrl = URL.createObjectURL(file.raw);
      },
      beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg';
        const isLt2M = file.size / 1024 / 1024 < 2;

        if (!isJPG) {
          this.$message.error('上传头像图片只能是 JPG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!');
        }
        return isJPG && isLt2M;
      }
    }
  }
</script>

<style scoped lang='stylus'>
h3 {
  font-size: 25px;
  text-align: center;
  margin-top: 20px;
  margin-bottom: 20px;
}

.setting {
  width: 450px;
  min-height: 400px;
  margin: 10px auto;
  background-color: #f9fafc;

  li {
    font-size: 20px;
    padding: 20px;
  }
   .avatar-uploader .el-upload {
    border: 1px dashed  black;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: red;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: black;
    width: 150px;
    height: 150px;
    line-height: 150px;
    text-align: center;
    border-radius 50%
  }
  .avatar {
    width: 150px;
    height: 150px;
    display: block;
    border-radius 50%
  }
}
</style>